//
//  HP_InstalmentListController.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/9/1.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "HP_InstalmentListController.h"
#import "HP_RecommendListTableViewCell.h"
#import "Mediator+Consume.h"

@interface HP_InstalmentListController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UIView *headerView;
@property(nonatomic,strong)UIButton *distanceBtn;
@property(nonatomic,strong)UIButton *priceBtn;
@property(nonatomic,strong)UIButton *periodsBtn;

@property(nonatomic,strong)UITableView *myTabelView;
@property(nonatomic,strong)NSMutableArray *dataArray;


@end

@implementation HP_InstalmentListController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViews];
}

-(void)initViews{
    [self.view addSubview:self.headerView];
    self.myTabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 45, ScreenWidthMao, ScreenHeight-64-45) style:UITableViewStylePlain];
    self.myTabelView.dataSource = self;
    self.myTabelView.delegate = self;
    [self.myTabelView registerClass:[HP_RecommendListTableViewCell class] forCellReuseIdentifier:@"HP_RecommendListTableViewCell"];
    [self.view addSubview:self.myTabelView];
    [self.myTabelView reloadData];
}
#pragma mark ----------tableViewDelegate---------------------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HP_RecommendListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HP_RecommendListTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 135;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UIViewController *detailVC = [[Mediator sharedInstance] Consume_goodsDetailViewController:@"id"];
    [self.navigationController pushViewController:detailVC animated:YES];
}


-(void)distanceBtnAction{
    self.distanceBtn.selected = YES;
    self.priceBtn.selected = NO;
    self.periodsBtn.selected = NO;
    [self.priceBtn setImage:[UIImage imageNamed:@"ic_descending order_def"] forState:UIControlStateNormal];
    [self.priceBtn setTitleColor:ThemeMaoBackgroundColor forState:UIControlStateNormal];
}
-(void)priceBtAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    [self.priceBtn setImage:[UIImage imageNamed:@"ic_descending order_xia"] forState:UIControlStateNormal];
    [self.priceBtn setImage:[UIImage imageNamed:@"ic_ascending order_shang"] forState:UIControlStateSelected];
    [self.priceBtn setTitleColor:ThemeMaoBlackColor forState:UIControlStateNormal];
    [self.priceBtn setTitleColor:ThemeMaoBlackColor forState:UIControlStateSelected];
    
    self.distanceBtn.selected = NO;
    self.periodsBtn.selected = NO;
    
    
}
-(void)periodsBtnAction{
    
    self.distanceBtn.selected = NO;
    self.priceBtn.selected = NO;
    self.periodsBtn.selected = YES;
    [self.priceBtn setImage:[UIImage imageNamed:@"ic_descending order_def"] forState:UIControlStateNormal];
    [self.priceBtn setTitleColor:ThemeMaoBackgroundColor forState:UIControlStateNormal];
}
-(UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc]init];
        _headerView.backgroundColor = [UIColor whiteColor];
        _headerView.frame = CGRectMake(0, 0, ScreenWidthMao, 42);
        _headerView.layer.shadowColor = HexColor(0x000000).CGColor;
        _headerView.layer.shadowOffset = CGSizeMake(0, 1);
        _headerView.layer.shadowOpacity = 0.15;
        _distanceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_distanceBtn setTitle:@"门店距离" forState:UIControlStateNormal];
        [_distanceBtn setTitleColor:ThemeMaoBackgroundColor forState:UIControlStateNormal];
        [_distanceBtn setTitleColor:ThemeMaoBlackColor forState:UIControlStateSelected];
        _distanceBtn.titleLabel.font = UIFontMaoNormal;
        _distanceBtn.frame = CGRectMake(0, 0, ScreenWidthMao/3, 42);
        [_distanceBtn addTarget:self action:@selector(distanceBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [_headerView addSubview:_distanceBtn];
        
        _priceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_priceBtn setTitle:@"商品价格" forState:UIControlStateNormal];
        [_priceBtn setTitleColor:ThemeMaoBackgroundColor forState:UIControlStateNormal];
        [_priceBtn setTitleColor:ThemeMaoBlackColor forState:UIControlStateSelected];
        [_priceBtn setImage:[UIImage imageNamed:@"ic_descending order_def"] forState:UIControlStateNormal];
//        [_priceBtn setImage:[UIImage imageNamed:@"ic_ascending order_shang order_xia"] forState:UIControlStateSelected];
        
        _priceBtn.titleLabel.font = UIFontMaoNormal;
        _priceBtn.frame = CGRectMake(ScreenWidthMao/3, 0, ScreenWidthMao/3, 42);
        [_priceBtn addTarget:self action:@selector(priceBtAction:) forControlEvents:UIControlEventTouchUpInside];
        [_headerView addSubview:_priceBtn];
        [_priceBtn layoutButtonWithEdgeInsetsStyle:XNButtonEdgeInsetsStyleRight imageTitleSpace:2];
        
        
        _periodsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_periodsBtn setTitle:@"分期期数" forState:UIControlStateNormal];
        [_periodsBtn setTitleColor:ThemeMaoBackgroundColor forState:UIControlStateNormal];
        [_periodsBtn setTitleColor:ThemeMaoBlackColor forState:UIControlStateSelected];
        _periodsBtn.titleLabel.font = UIFontMaoNormal;
        _periodsBtn.frame = CGRectMake(ScreenWidthMao/3*2, 0, ScreenWidthMao/3, 42);
        [_periodsBtn addTarget:self action:@selector(periodsBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [_headerView addSubview:_periodsBtn];
        
        self.distanceBtn.selected = YES;
    }
    
    return _headerView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
